<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改展会名单')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<!--    <form class="form-horizontal m" id="form-eventsort-edit" th:object="${eventSort}">-->
<!--        <input id="sortId" name="sortId" type="hidden" th:field="*{sortId}"/>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label is-required">展会分类名称：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input class="form-control" type="text" name="sortName" id="sortName" th:field="*{sortName}" required>-->
<!--            </div>-->
<!--        </div>-->
    <form class="form-horizontal m" id="form-eventRoster-edit" th:object="${eventRoster}">
        <input name="deptId" type="hidden" id="treeId"/>
        <div class="row">
            <div class="col-sm-6">
                <input id="rosterId" name="rosterId" type="hidden" th:field="*{rosterId}"/>
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">展会名称：</label>
                    <div class="col-sm-8">
                        <input name="eventName" placeholder="请输入展会名称" class="form-control" type="text" maxlength="30" th:field="*{eventName}" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">展会分类：</label>
                    <div class="col-sm-8">
                        <select id="sortId" name="sortId" class="form-control m-b">
                            <option th:each="post:${eventSort}" th:value="${post.sortId}" th:text="${post.sortName}" th:field="*{sortId}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">展会时间：</label>
                    <div class="col-xs-10">
                        <input type="text" class="time-input"  th:value="${#dates.format(eventRoster.startTime,'yyyy-MM-dd HH:mm:ss')}" id="startTime" placeholder="开始时间" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                        <span>-</span>
                        <input type="text" class="time-input" th:value="${#dates.format(eventRoster.endTime,'yyyy-MM-dd HH:mm:ss')}" id="endTime" placeholder="结束时间" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss" />
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">展会简介：</label>
                    <div class="col-xs-10">
                        <textarea id="eventProfiles" name="eventProfiles" maxlength="500" class="form-control" rows="3" th:field="*{eventProfiles}"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">展会地址：</label>
                    <div class="col-xs-10">
                        <textarea id="eventAddress" name="eventAddress" maxlength="500" class="form-control" rows="3" th:field="*{eventAddress}"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "system/eventRoster";
    //  $(function() {
    // 	var url = ctx + "system/menu/roleMenuTreeData?sortId=" + $("#sortId").val();
    // 	var options = {
    // 		id: "menuTrees",
    //         url: url,
    //         check: { enable: true },
    //         expandLevel: 0
    //     };
    // 	$.tree.init(options);
    // });

    $("#form-eventRoster-edit").validate({
        onkeyup: false,
        rules:{
            eventName:{
                minlength: 2,
                maxlength: 20,
                remote: {
                    url: prefix + "/checkEventNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "rosterId": function() {
                            return $("#rosterId").val();
                        },
                        "eventName": function() {
                            return $.common.trim($("#eventName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "eventName": {
                remote: "展会名单名称已经存在"
            }
        },
        focusCleanup: true
    });

    $('input').on('ifChanged', function(obj){
        var type = $(this).val();
        var checked = obj.currentTarget.checked;
        if (type == 1) {
            if (checked) {
                $._tree.expandAll(true);
            } else {
                $._tree.expandAll(false);
            }
        } else if (type == "2") {
            if (checked) {
                $._tree.checkAllNodes(true);
            } else {
                $._tree.checkAllNodes(false);
            }
        } else if (type == "3") {
            if (checked) {
                $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
            } else {
                $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
            }
        }
    })

    function edit() {
        var rosterId = $("input[name='rosterId']").val();
        var sortId = document.getElementById("sortId").value;
        var eventName = $("input[name='eventName']").val();
        var eventProfiles = document.getElementById("eventProfiles").value;
        var eventAddress = document.getElementById("eventAddress").value;
        var startTime = document.getElementById("startTime").value;
        var endTime = document.getElementById("endTime").value;
        $.ajax({
            cache : true,
            type : "POST",
            url : prefix + "/edit",
            data : {
                "rosterId": rosterId,
                "eventName": eventName,
                "sortId": sortId,
                "eventProfiles": eventProfiles,
                "eventAddress": eventAddress,
                "startTime": startTime,
                "endTime": endTime
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }
</script>
</body>
</html>
